﻿/*
____
 L|ypps Web controls for ASP.NET

Copyright (c) 2009 Alessandro Zifiglio, http://www.Typps.com
EMail: alessandro@Typps.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
namespace Typps
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    public partial class FormCss : Form
    {
        #region Fields

        private static readonly object cssSelectedIndexChangedEventHandlerValue = new object();
        private static readonly object whiteSpaceCheckedChangedEventHandlerValue = new object();

        #endregion Fields

        #region Constructors

        public FormCss(CssSelection css)
        {
            InitializeComponent();
            switch (css)
            {
                case CssSelection.HtmlEditor:
                    this.comboBoxCss.Items.AddRange(new object[] {
                            "HtmlEditor"});
                    break;
                case CssSelection.ImagePicker:
                    this.comboBoxCss.Items.AddRange(new object[] { "ImagePicker"});
                    break;
                case CssSelection.MediaFrame:
                    this.comboBoxCss.Items.AddRange(new object[] { "MediaFrame"});
                    break;
                case CssSelection.ColorPicker:
                    this.comboBoxCss.Items.AddRange(new object[] { "ColorPicker"});
                    break;
                case CssSelection.UpdatePanelProgress:
                    this.comboBoxCss.Items.AddRange(new object[] { "UpdatePanelProgress" });
                    break;
                case CssSelection.SlidePane:
                    this.comboBoxCss.Items.AddRange(new object[] { "SlidePane"});
                    break;
            }
            if (this.comboBoxCss.Items.Count > 0)
                this.comboBoxCss.SelectedIndex = 0;
        }

        #endregion Constructors

        #region Events

        [Category("Action"),
        Description("CssSelectedIndexChanged Event")]
        public event CssSelectedIndexChangedEventHandler CssSelectedIndexChanged
        {
            add
            {
                base.Events.AddHandler(cssSelectedIndexChangedEventHandlerValue, value);
            }
            remove
            {
                base.Events.RemoveHandler(cssSelectedIndexChangedEventHandlerValue, value);
            }
        }

        [Category("Action"),
        Description("CheckedChanged Event")]
        public event WhiteSpaceCheckedChangedEventHandler WhiteSpaceCheckedChanged
        {
            add
            {
                base.Events.AddHandler(whiteSpaceCheckedChangedEventHandlerValue, value);
            }
            remove
            {
                base.Events.RemoveHandler(whiteSpaceCheckedChangedEventHandlerValue, value);
            }
        }

        #endregion Events

        #region Methods

        internal bool IsWhiteSpaceRemovalChecked()
        {
            return checkBox1.Checked;
        }

        internal void SetCss(string css)
        {
            textBoxCss.Text = css;
        }

        protected virtual void OnCssSelectedIndexChanged(CssSelectedIndexChangedEventArgs e)
        {
            CssSelectedIndexChangedEventHandler handler = (CssSelectedIndexChangedEventHandler)base.Events[cssSelectedIndexChangedEventHandlerValue];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnWhiteSpaceCheckedChanged(WhiteSpaceCheckedChangedEventArgs e)
        {
            WhiteSpaceCheckedChangedEventHandler handler = (WhiteSpaceCheckedChangedEventHandler)base.Events[whiteSpaceCheckedChangedEventHandlerValue];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            textBoxCss.Clear();
            this.Close();
        }

        private void buttonCopy_Click(object sender, EventArgs e)
        {
            Clipboard.SetDataObject(textBoxCss.Text);
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            CssSelection cs = (CssSelection)Enum.Parse(typeof(CssSelection), comboBoxCss.SelectedItem.ToString());
            OnWhiteSpaceCheckedChanged(new WhiteSpaceCheckedChangedEventArgs(checkBox1.Checked, cs));
        }

        private void comboBoxCss_SelectedIndexChanged(object sender, EventArgs e)
        {
            CssSelection cs = (CssSelection)Enum.Parse(typeof(CssSelection), comboBoxCss.SelectedItem.ToString());
            OnCssSelectedIndexChanged(new CssSelectedIndexChangedEventArgs(cs, textBoxCss.Text));
        }

        #endregion Methods
    }
}